namespace Vanilla

import System.IO as Sys

// File
class File:
	// Gets the full path to the file
	public Path as string
	
	// Gets the file's type
	public Type as FileType:
		get:
			return FileTypes.Ext[Sys.Path.GetExtension(Name)] if FileTypes.Ext.ContainsKey(Sys.Path.GetExtension(Name))
			return FileTypes.Named["Directory"] if Sys.Directory.Exists(Path)
			return FileTypes.Named["File"]
	
	// Open the file with the default application or itself
	def Open ():
		t = Type
		if t.IsAlso("Tool"):
			(Tool.LoadTool(self) as IOpen).Open()
		else:
			(t.ToolForAction("Open") as IOpenFile).OpenFile(self)
			
	// The name of this file (not including the path)
	public Name as string:
		get:
			return Sys.Path.GetFileName(Path)
	
	// This user's home directory
	static Home as File:
		get:
			return File(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal))
	
	// True if it is a directory
	public HasContents as bool:
		get:
			return Sys.Directory.Exists(Path)
	
	// True if it is a file
	public HasData as bool:
		get:
			return Sys.File.Exists(Path)
	
	// True if it's a hidden file/folder
	public IsHidden as bool:
		get:
			return Name.StartsWith(".")
	
	// Gets the contents
	Contents as (File):
		get:
			return array(File,0) unless HasContents
			
			e = Sys.Directory.GetFileSystemEntries(Path)
			f = array(File,0)
			for file in e:
				f += (File(file),)
			return f
			
	
	//def constructor (d as Directory, n as string):
	//	Directory = d
	//	Name = n
	
	def constructor (p as string):
		Path = p
		//self(Directory(Sys.Path.GetDirectoryName(path)), Sys.Path.GetFileName(path))
	
	//static def constructor ():
	//	FileTypes.Init()
	
	public Parent as File:
		get:
			return File(Sys.Path.GetDirectoryName(Path))

/*
// DIRECTORY
class Directory (FileInfo):
	Up as File:
		get:
			return Parent
	
	Exists as bool:
		get:
			return Sys.Directory.Exists(Path)
	
	Files as (FileInfo):
		get:
			return Contents
	
	def OpenSubFile (n as string):
		return File(Sys.Path.Combine(Path, n))
	
	
	def constructor (p as string):
		super(p)

// FILE
class File (FileInfo):
	def constructor (p as string):
		super(p)
*/
